import { getTreeDataType, getTreeDataTypeDoff } from '@/utils/tool';
import { makeAutoObservable } from 'mobx';
import { Storage } from '@/utils/storage';
import { handleFlawFilterData } from '@/components/FlawFilterPmp/tool';

//缺陷筛选中的前置层、POL、偏贴后(所有数据)
export const commonStore = makeAutoObservable({
  doffResult:{ modeTreeData: {}, fatherMap: {}, flawTypeSymbolMap: {}, stationMap: {} },
  polResult: Storage.get('layerIdFlawType') ? getTreeDataType(Storage.get('layerIdFlawType').pol) : { modeTreeData: {}, fatherMap: {}, flawTypeSymbolMap: {} },
  pianResult: Storage.get('layerIdFlawType') ? getTreeDataType(Storage.get('layerIdFlawType').piantiehou) : { modeTreeData: {}, fatherMap: {}, flawTypeSymbolMap: {} },
  FlawTypePmpConf: [] as Array<any>,
  FlawTypePmpGobal: {
    fatherFlawTrue: {}, //父缺陷全选
    fatherFlawFalse: {}, //父缺陷全选
    sonFlawTrue: {}, // 所有的子缺陷全部选中
    sonFlawFalse: {}, // 所有的子缺陷全部不选中
    checkLV1: {}, // 所有的lv1缺陷是哪些
    checkLV2: {}, // 所有的lv2缺陷是哪些
    checkLV3: {}, // 所有的lv3缺陷是哪些
    defaultFlaw: {}, // 默认选中的lv1缺陷 { 1000:[1001], 1100:[1101], 1200:[1201] }
    defaultFlawArr: [] as Array<number>, // 默认选中的lv1缺陷 [ 1001,1101,1201 ]
    hasChildNum: {} // 每个父缺陷有几个子缺陷
  },
  setFlawType() {},
  setDefaultSetting(flawTypeConf, sysMapStore, lotStore) {
    this.changeFlawTypePmpConf(flawTypeConf, sysMapStore, lotStore);
    this.doffResult = getTreeDataTypeDoff(flawTypeConf.doff);// 这个不能删除，留着卷详情--缺陷卡片上3301:缺陷名
    this.polResult = getTreeDataType(flawTypeConf.pol);
    this.pianResult = getTreeDataType(flawTypeConf.piantiehou);
  },
  changeFlawTypePmpConf(flawTypeConf, sysMapStore, lotStore) {
    this.FlawTypePmpConf = flawTypeConf.doff;
    const flawFilter = handleFlawFilterData(flawTypeConf.doff);
    const cacheData1 = Storage.get('map_checkedFlawType');
    const cacheData2 = Storage.get('lotId_checkedFlawType');
    if (!cacheData1) {
      sysMapStore.changeCheckedFlawType(flawFilter.defaultFlawArr);
    }
    if (!cacheData2) {
      lotStore.changeCheckedFlawType(flawFilter.defaultFlawArr);
    }
    this.FlawTypePmpGobal.fatherFlawTrue = flawFilter.fatherFlawTrue;
    this.FlawTypePmpGobal.fatherFlawFalse = flawFilter.fatherFlawFalse;
    this.FlawTypePmpGobal.sonFlawTrue = flawFilter.sonFlawTrue;
    this.FlawTypePmpGobal.sonFlawFalse = flawFilter.sonFlawFalse;
    this.FlawTypePmpGobal.checkLV1 = flawFilter.checkLV1;
    this.FlawTypePmpGobal.checkLV2 = flawFilter.checkLV2;
    this.FlawTypePmpGobal.checkLV3 = flawFilter.checkLV3;
    this.FlawTypePmpGobal.defaultFlaw = flawFilter.defaultFlaw;
    this.FlawTypePmpGobal.defaultFlawArr = flawFilter.defaultFlawArr;
    this.FlawTypePmpGobal.hasChildNum = flawFilter.hasChildNum;
  }
});

export default commonStore;
